<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>查询用户</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <!--<link href="css/nprogress.css" rel="stylesheet">-->
    <!-- FullCalendar -->
    <link href="css/fullcalendar.min.css" rel="stylesheet">
    <link href="css/fullcalendar.print.css" rel="stylesheet" media="print">
    <style>
    	
    	#bbb{
    		margin: 2px 90px;
    		float: left;
    		display: none;
    	}
      td{
        text-align: center;
      }
        th{
          text-align: center;
        }
    </style>
	
		
    <!-- Custom styling plus plugins -->
    <link href="css/custom.min.css" rel="stylesheet">
  </head>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
       <div id="head">
       	
       </div>

        

        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left" style="margin-bottom: 20px;">
              	<h3 style="color: green;">用户查询</h3>
				<hr />
              </div>

              <div style="float: left;margin: 0 auto;margin-left: 300px;margin-bottom: 35px;">
              <form style="font-size: 15px;">
				 
				  <input type="text" placeholder="用户名" id="uname" style="width: 200px;height: 40px;"/>
				  <select style="width: 100px;height: 40px;margin-top: 20px;" id="s_province" name="s_province">
					<option value="">请选择</option>

				  </select>
				  
				  <select style="width: 100px;height: 40px;margin-top: 20px;" id="utype">
				  	<option value="">请选择</option>

				  </select>
				  <div style="display: inline-block;">
				  		<button type="button" class="btn btn-info userQuery" >开始查询</button>
				  	</div>
			  </form>
    			</div>						
    										
            </div>
				
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12">
                <div class="x_panel">
                  <div class="x_title">
                    
                    
                      
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">


                    <!-- start project list -->
                    <table class="table table-striped projects" id="table1">
						<button type="button" class="btn btn-info" style="float: right;" id="insertUser">新增用户</button>
                      <thead>
                        <tr>
                          <th style="width: 6%">用户名</th>
                          <th style="width: 6%">真实姓名</th>
                          <th style="width: 10%;text-align: center;">邮件地址</th>
                          <th style="width: 12%;text-align: center;">身份证号</th>
                          <th style="width: 8%;text-align: center;">联系方式</th>
                          <th style="width: 6%">用户类型</th>	
                          <th style="width: 12%">详细地址</th>
                          <th style="width: 15%;text-align: center;">操作</th>
                        </tr>
                      </thead>


                    </table>
                   
													<!-- 1111 -->
													<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-hidden="true" style="display: none;">
                    <div class="modal-dialog modal-sm">
                      <div class="modal-content">

                        <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
                          </button>
                          <h4 class="modal-title" id="myModalLabel3">重置密码</h4>
                        </div>
                        <div class="modal-body">
                        	确定要重置该用户的密码？
                        </div>
                        <div class="modal-footer">
                          <button type="button" class="btn btn-default"  id="yes">确定</button>
                          <button type="button" class="btn btn-default" data-dismiss="modal" onclick="window.history.back(-1)">关闭</button>
                        </div>

                      </div>
                    </div>
                  </div>

                  </div>
                </div>
              </div>
          </div>
        </div>
        <!-- /page content -->

        <!-- footer content -->
       
   
          <div class="pull-right" style="margin-bottom: 5px;	" >
							<ul class="pagination" id="ye" >
							</ul>
          </div>
          <!--<div class="clearfix"></div>-->
       
        <!-- /footer content -->
      </div>
    </div>

    <!-- calendar modal -->
    <div id="CalenderModalNew" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">

          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h4 class="modal-title" id="myModalLabel">New Calendar Entry</h4>
          </div>
          <div class="modal-body">
            <div id="testmodal" style="padding: 5px 20px;">
              <form id="antoform" class="form-horizontal calender" role="form">
                <div class="form-group">
                  <label class="col-sm-3 control-label">Title</label>
                  <div class="col-sm-9">
                    <input type="text" class="form-control" id="title" name="title">
                  </div>
                </div>
                <div class="form-group">
                  <label class="col-sm-3 control-label">Description</label>
                  <div class="col-sm-9">
                    <textarea class="form-control" style="height:55px;" id="descr" name="descr"></textarea>
                  </div>
                </div>
              </form>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default antoclose" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary antosubmit">Save changes</button>
          </div>
        </div>
      </div>
    </div>
    <div id="CalenderModalEdit" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">

          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h4 class="modal-title" id="myModalLabel2">Edit Calendar Entry</h4>
          </div>
          <div class="modal-body">

            <div id="testmodal2" style="padding: 5px 20px;">
              <form id="antoform2" class="form-horizontal calender" role="form">
                <div class="form-group">
                  <label class="col-sm-3 control-label">Title</label>
                  <div class="col-sm-9">
                    <input type="text" class="form-control" id="title2" name="title2">
                  </div>
                </div>
                <div class="form-group">
                  <label class="col-sm-3 control-label">Description</label>
                  <div class="col-sm-9">
                    <textarea class="form-control" style="height:55px;" id="descr2" name="descr"></textarea>
                  </div>
                </div>

              </form>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default antoclose2" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary antosubmit2">Save changes</button>
          </div>
        </div>
      </div>
    </div>
    </div>
    <div id="fc_create" data-toggle="modal" data-target="#CalenderModalNew"></div>
    <div id="fc_edit" data-toggle="modal" data-target="#CalenderModalEdit"></div>
    <!-- /calendar modal -->
        
    <!-- jQuery -->
    <script src="js/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="js/fastclick.js"></script>
    <!-- NProgress -->
    <script src="js/nprogress.js"></script>
    <!-- FullCalendar -->
    <script src="js/moment.min.js"></script>
    <script src="js/fullcalendar.min.js"></script>
    <script src="js/icheck.min.js"></script>
    <script src="js/area1.ui.js"></script>
    <!-- Custom Theme Scripts -->
    <!--<script src="js/custom.min.js"></script>-->
	
		<style >
			.checkbox-custom {
    position: relative;
    padding: 0 15px 0 25px;
    margin-bottom: 7px;
    margin-top: 0;
    display: inline-block;
}
/*
将初始的checkbox的样式改变
*/
.checkbox-custom input[type="checkbox"] {
    opacity: 0;/*将初始的checkbox隐藏起来*/
    position: absolute;
    cursor: pointer;
    z-index: 2;
    margin: -6px 0 0 0;
    top: 50%;
    left: 3px;
}
/*
设计新的checkbox，位置
*/
.checkbox-custom label:before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    margin-top: -9px;
    width: 19px;
    height: 18px;
    display: inline-block;
    border-radius: 2px;
    border: 1px solid #bbb;
    background: #eee;
}
/*
点击初始的checkbox，将新的checkbox关联起来
*/
.checkbox-custom input[type="checkbox"]:checked +label:after {
    position: absolute;
    display: inline-block;
    font-family: 'Glyphicons Halflings';
    content: "\e013";
    top: 48%;
    left: 4px;
    margin-top: -5px;
    font-size: 11px;
    line-height: 1;
    width: 16px;
    height: 16px;
    color: #333;
}
.checkbox-custom label {
    cursor: pointer;
    line-height: 1.2;
    font-weight: normal;/*改变了rememberme的字体*/
    margin-bottom: 0;
    text-align: left;
}
			
		</style>
    <!-- FullCalendar -->
    <script>
      $(window).load(function() {
          $("#head").load("head.html");
          $("#insertUser").click(function () {
              window.location.href = 'addUser.html';
          })
          var date = new Date(),
              d = date.getDate(),
              m = date.getMonth(),
              y = date.getFullYear(),
              started,
              categoryClass;

          var calendar = $('#calendar').fullCalendar({
              header: {
                  left: 'prev,next today',
                  center: 'title',
                  right: 'month,agendaWeek,agendaDay'
              },
              selectable: true,
              selectHelper: true,
              select: function (start, end, allDay) {
                  $('#fc_create').click();

                  started = start;
                  ended = end;

                  $(".antosubmit").on("click", function () {
                      var title = $("#title").val();
                      if (end) {
                          ended = end;
                      }

                      categoryClass = $("#event_type").val();

                      if (title) {
                          calendar.fullCalendar('renderEvent', {
                                  title: title,
                                  start: started,
                                  end: end,
                                  allDay: allDay
                              },
                              true // make the event "stick"
                          );
                      }

                      $('#title').val('');

                      calendar.fullCalendar('unselect');

                      $('.antoclose').click();

                      return false;
                  });
              },
              eventClick: function (calEvent, jsEvent, view) {
                  $('#fc_edit').click();
                  $('#title2').val(calEvent.title);

                  categoryClass = $("#event_type").val();

                  $(".antosubmit2").on("click", function () {
                      calEvent.title = $("#title2").val();

                      calendar.fullCalendar('updateEvent', calEvent);
                      $('.antoclose2').click();
                  });

                  calendar.fullCalendar('unselect');
              },
              editable: true,
              events: [{
                  title: 'All Day Event',
                  start: new Date(y, m, 1)
              }, {
                  title: 'Long Event',
                  start: new Date(y, m, d - 5),
                  end: new Date(y, m, d - 2)
              }, {
                  title: 'Meeting',
                  start: new Date(y, m, d, 10, 30),
                  allDay: false
              }, {
                  title: 'Lunch',
                  start: new Date(y, m, d + 14, 12, 0),
                  end: new Date(y, m, d, 14, 0),
                  allDay: false
              }, {
                  title: 'Birthday Party',
                  start: new Date(y, m, d + 1, 19, 0),
                  end: new Date(y, m, d + 1, 22, 30),
                  allDay: false
              }, {
                  title: 'Click for Google',
                  start: new Date(y, m, 28),
                  end: new Date(y, m, 29),
                  url: 'http://google.com/'
              }]
          });
          var $token = window.sessionStorage.getItem('token');
          $.ajax({
              type: "post",
              xhrFields: {withCredentials: true},
              url: "http://localhost:8081/userInfo/userType",
              dataType: "json",
              data: {"token": $token},
              success: function (data) {
                  $.each(data, function (i, depot) {
                      var $op = '<option value="' + depot.id + '">' + depot.typename + '</option>';
                      $("#utype").append($($op));
                  })
              },
              error: function () {
                  alert("用户类型加载错误");
              }
          })
          $.ajax({
              type: "post",
              xhrFields: {withCredentials: true},
              url: "http://localhost:8081/userInfo/toUserInfo",
              dataType: "json",
              data: {"token": $token},
              success: function (data) {
                  if (data.list == null) {
                      $("#table1").html('<td colspan="8">未查到数据</td>');
                      return;
                  }
                  $('#table1 tbody').remove();
                  $.each(data.list, function (i, depot) {
                      var $tr = $('<tr></tr>');

                      var $td = $('<td></td>');
                      $td.text(depot.username);
                      $tr.append($td);
                      if (depot.salesman != null) {
                          $td = $('<td></td>');
                          $td.text(depot.salesman.sName);
                          $tr.append($td);
                      } else {
                          $td = $('<td></td>');
                          $td.text("");
                          $tr.append($td);
                      }
                      if (depot.salesman != null) {
                          $td = $('<td></td>');
                          $td.text(depot.salesman.sEmail);
                          $tr.append($td);
                      } else {
                          $td = $('<td></td>');
                          $td.text("");
                          $tr.append($td);
                      }
                      if (depot.salesman != null) {
                          $td = $('<td></td>');
                          $td.text(depot.salesman.sIdcard);
                          $tr.append($td);
                      } else {
                          $td = $('<td></td>');
                          $td.text("");
                          $tr.append($td);
                      }
                      $td = $('<td></td>');
                      $td.text(depot.phone);
                      $tr.append($td);

                      $td = $('<td></td>');
                      $td.text(depot.userType);
                      $tr.append($td);
                      if (depot.salesman != null) {
                          $td = $('<td></td>');
                          $td.text(depot.salesman.sAddress);
                          $tr.append($td);
                      } else {
                          $td = $('<td></td>');
                          $td.text("");
                          $tr.append($td);
                      }
                      if(depot.typeid!=1&&depot.typeid!=10) {
                          $td = $('<td></td>');
                          $td.html('<a href="javascript:;" id="update1" class="btn btn-dark btn-xs" uid="' + depot.id + '" style="padding: 2px 8px;">修改</a>\n' +
                              '\t\t\t\t\t    \t<a href="javascript:;" id="delete1" class="btn btn-danger btn-xs" style="padding: 2px 8px;" uid="' + depot.id + '" uname="'+depot.username+'">删除</a>\n' +
                              '\t\t\t\t\t    \t<a href="javascript:;" id="cz1" class="btn btn-warning btn-xs" style="padding: 2px 8px;"  uid="' + depot.id + '" uname="'+depot.username+'">重置密码</a>');
                          $tr.append($td);
                      } if(depot.typeid==10){
                          $td = $('<td ></td >');
                          $td.html('<a href="javascript:;" id="delete1" class="btn btn-danger btn-xs" style="padding: 2px 8px;" uid="'+depot.id+'" uname="'+depot.username+'">删除</a>\n' +
                              '\t\t\t\t\t    \t<a href="javascript:;" id="cz1" class="btn btn-warning btn-xs" style="padding: 2px 8px;"  uid="'+depot.id+'" uname="'+depot.username+'">重置密码</a>');
                          $tr.append($td);
                      }
                      $('#table1').append($tr);
                  })
                  $('#ye').prepend('<li><a class="userQuery" href="javascript:;" pageNum="' + (data.pageNum - 1) + '" >&laquo;</a></li >');
                  $("#ye").append('<li><a>' + data.pageNum + "/" + data.pages + '</a></li>');
                  $('#ye').append('<li><a class="userQuery" href="javascript:;" pageNum="' + (data.pageNum + 1) + '">&raquo;</a></li>');
              },
              error: function () {
                  alert("错误");
              }
          })
          $(document).on("click", ".userQuery", function () {
              var $pagenum = $(this).attr("pagenum");
              var $uname = $("#uname").val();
              var $uaddress = $("#s_province").val();
              var $utype = $("#utype").val();
              $.ajax({
                  type: "post",
                  xhrFields: {withCredentials: true},
                  url: "http://localhost:8081/userInfo/toUserInfo",
                  dataType: "json",
                  data: {
                      "token": $token,
                      "userName": $uname,
                      "sAddress": $uaddress,
                      "typeId": $utype,
                      "pageNum": $pagenum
                  },
                  success: function (data) {
                      if (data.list == null) {
                          $("#table1").html('<td colspan="8">未查到数据</td>');
                          return;
                      }
                      $('#table1 tbody').remove();
                      $('#ye li').remove();
                      $.each(data.list, function (i, depot) {
                          var $tr = $('<tr></tr>');

                          var $td = $('<td></td>');
                          $td.text(depot.username);
                          $tr.append($td);
                          if (depot.salesman != null) {
                              $td = $('<td></td>');
                              $td.text(depot.salesman.sName);
                              $tr.append($td);
                          } else {
                              $td = $('<td></td>');
                              $td.text("");
                              $tr.append($td);
                          }
                          if (depot.salesman != null) {
                              $td = $('<td></td>');
                              $td.text(depot.salesman.sEmail);
                              $tr.append($td);
                          } else {
                              $td = $('<td></td>');
                              $td.text("");
                              $tr.append($td);
                          }
                          if (depot.salesman != null) {
                              $td = $('<td></td>');
                              $td.text(depot.salesman.sIdcard);
                              $tr.append($td);
                          } else {
                              $td = $('<td></td>');
                              $td.text("");
                              $tr.append($td);
                          }
                          $td = $('<td></td>');
                          $td.text(depot.phone);
                          $tr.append($td);

                          $td = $('<td></td>');
                          $td.text(depot.userType);
                          $tr.append($td);
                          if (depot.salesman != null) {
                              $td = $('<td></td>');
                              $td.text(depot.salesman.sAddress);
                              $tr.append($td);
                          } else {
                              $td = $('<td></td>');
                              $td.text("");
                              $tr.append($td);
                          }
                          if(depot.typeid!=1&&depot.typeid!=10){
                              $td = $('<td></td>');
                          $td.html('<a href="javascript:;" id="update1" class="btn btn-dark btn-xs" style="padding: 2px 8px;" uid="'+depot.id+'">修改</a>\n' +
                              '\t\t\t\t\t    \t<a href="javascript:;" id="delete1" class="btn btn-danger btn-xs" style="padding: 2px 8px;" uid="'+depot.id+'" uname="'+depot.username+'">删除</a>\n' +
                              '\t\t\t\t\t    \t<a href="javascript:;" id="cz1" class="btn btn-warning btn-xs" style="padding: 2px 8px;"  uid="'+depot.id+'" uname="'+depot.username+'">重置密码</a>');
                          $tr.append($td);
                          }
                          if(depot.typeid==10){
                              $td = $('<td ></td>');
                              $td.html('<a href="javascript:;" id="delete1" class="btn btn-danger btn-xs" style="padding: 2px 8px;" uid="'+depot.id+'" uname="'+depot.username+'">删除</a>\n' +
                                  '\t\t\t\t\t    \t<a href="javascript:;" id="cz1" class="btn btn-warning btn-xs" style="padding: 2px 8px;"  uid="'+depot.id+'" uname="'+depot.username+'">重置密码</a>');
                              $tr.append($td);
                          }
                          $('#table1').append($tr);
                      })
                      $('#ye').prepend('<li><a class="userQuery" href="javascript:;" pageNum="' + (data.pageNum - 1) + '" >&laquo;</a></li >');
                      $("#ye").append('<li><a>' + data.pageNum + "/" + data.pages + '</a></li>');
                      $('#ye').append('<li><a class="userQuery" href="javascript:;" pageNum="' + (data.pageNum + 1) + '">&raquo;</a></li>');
                  },
                  error: function () {
                      alert("错误");
                  }
              })
          })

          $(function () {
              $(document).area("s_province", "s_city", "s_county");//调用插件
              $('.cancel').click(function () {
                  var str = "";
                  $('#s_province').children().each(function () {
                      if ($(this).prop('selected') == true) {
                          str += $(this).html();
                      }
                  });

                  str += document.getElementByItById('all').value;
                  $('#time').val(str);

              });
              $("#s_province").children("option:last-child").val("");
              $("#s_province").children("option:last-child").attr("selected",true);
          });
//地区三级联动结速
//           重置密码
          $(document).on("click", "#cz1", function () {
              var $uname=$(this).attr("uname");
              var $id=$(this).attr("uid");
              if(confirm("是否要重置"+$uname+"的密码")){
              $.ajax({
                  type: "post",
                  xhrFields: {withCredentials: true},
                  url: "http://localhost:8081/userInfo/Reset",
                  dataType: "JSON",
                  data: {
                      "token": $token,
                      "id": $id
                  },
                  success:function(data) {
                        if(data.message=="yes"){
                            alert("重置密码成功,修改密码为111111");
                        }else{
                            alert("重置密码失败");
                        }
                  },
                  error: function () {
                      alert("重置密码错误");
                  }
              })

              }
          })
          //点击修改
          $(document).on("click", "#update1", function () {
              var $id=$(this).attr("uid");
              window.location.href="updateUserInfor.html?id="+$id;
          })

          //点击删除
          $(document).on("click", "#delete1", function () {
              var $id=$(this).attr("uid");
              var obj=$(this);
              var $uname=$(this).attr("uname");
              if(confirm("是否要删除"+$uname+"")){
                  $.ajax({
                      type: "post",
                      xhrFields: {withCredentials: true},
                      url: "http://localhost:8081/userInfo/delUser",
                      dataType: "JSON",
                      data: {
                          "token": $token,
                          "id": $id
                      },
                      success:function(data) {
                          if(data.message=="yes"){
                              alert("删除成功");
                              obj.parent().parent("tr").remove();
                          }else{
                              alert("删除失败");
                          }
                      },
                      error: function () {
                          alert("删除错误");
                      }
                  })

              }
          })










      });
    </script>
    <!-- /FullCalendar -->
  </body>
</html>
